﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using SharpTrainer.Util;
using Zeus.Thunder.Core;

namespace SharpTrainer.Other
{
    class LinqXmlTest : ITestCase
    {
        public void Run()
        {
            var doc = XDocument.Load("Products.xml");
            var products = doc.Element("Products").Elements();
            var cheap = from product in products
                        let name = product.Attribute("Name").Value
                        let price = decimal.Parse(product.Attribute("Price").Value)
                        where price < 25m
                        select new Product { Name = name, Price = price };

            Console.WriteLine("Cheap:");
            Display(cheap);
        }

        private void Display(IEnumerable<Product> products)
        {
            GenericUtil<Product>.PrintEnumerable(products);
        }
    }
}
